package com.rabbitmq.exec.ttl;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.rabbitmq.exec.utils.RabbitMqUtils;

import java.nio.charset.StandardCharsets;

/**
 * @Description
 * @Author lhj
 * @Date 2024/4/19 8:36
 */
public class Consumer02 {

    public static final String DEAD_EXCHANGE_NAME = "dead_exchange";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        channel.exchangeDeclare(DEAD_EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        String deadQueue = "dead-queue";
        channel.queueDeclare(deadQueue, true, false, false, null);
        channel.queueBind(deadQueue, DEAD_EXCHANGE_NAME, "lisi");

        DeliverCallback deliverCallback = ((consumerTag, message) -> {
            String msg = new String(message.getBody(), StandardCharsets.UTF_8);
            System.out.println(String.format("消费者02 接收到消息: %s, queueName: %s, exchangeName: %s", msg, deadQueue, DEAD_EXCHANGE_NAME));
        });
        
        channel.basicConsume(deadQueue, true, deliverCallback, consumerTag -> {});
    }
    
}
